use std::{thread, time};

#[test]
fn test_loop() {
    let mut optional = Some(0);
    loop {
        match optional {
            Some(i) => {
                if i > 9 {
                    println!("Greater than 9, quit!");
                    optional = None;
                } else {
                    println!("`i` is `{:?}`. Try again", i);
                    optional = Some(i + 1);
                    thread::sleep(time::Duration::from_millis(1000));
                }
            }
            None => {
                break;
            }
        }
    }
}
// 使用 while let 可以使这段代码变得更加优雅：
#[test]
fn test_while_let() {
    let mut optional = Some(0);

    while let Some(i) = optional {
        if i > 9 {
            println!("Greater than 9, quit!");
            optional = None;
        } else {
            println!("`i` is `{:?}`. Try again", i);
            optional = Some(i + 1);
            thread::sleep(time::Duration::from_millis(1000));
        }
    }
}